import Vuex from "vuex";
import Vue from "vue";
import getters from "./getters.js";
import createPersistedState from 'vuex-persistedstate'; // 引入数据持久化模块
Vue.use(Vuex)
// modules
import user from "./user/index.js";
import app from "./app/index.js";

const store = new Vuex.Store({
	modules: {
		user,
		app
	},
	getters,
	// 数据持久化
	plugins: [
		createPersistedState({
			storage: { // 存储方式定义  
				getItem: (key) => uni.getStorageSync(key), // 获取  
				setItem: (key, value) => uni.setStorageSync(key, value), // 存储  
				removeItem: (key) => uni.removeStorageSync(key) // 删除  
			}
		}),
	],
});

export default store;
